//
// Created by jiazhong on 2023/11/8.
//

#ifndef MEDIASTUDY_X264HELPER_H
#define MEDIASTUDY_X264HELPER_H

// 如果引入需要带路径的话，是因为没有build成功。重新build即可
#include "x264.h"
#include "JavaCallHelper.h"
#include "RtmpHelper.h"

class X264Helper {

public:
    JavaCallHelper *javaCallHelper = nullptr;
    RtmpHelper *rtmpHelper = nullptr;

    // 创建x264编码器
    int setVideoEncInfo(int width, int height, int fps, int bitrate);

    // 真正开始编码一帧数据
    void encodeData(int8_t *data, int len, int type);

    // 发送sps pps
    void sendSpsPps(uint8_t *sps, uint8_t *pps, int sps_len, int pps_len);

    // 发送帧   关键帧 和非关键帧
    void sendFrame(int type, int payload, uint8_t *p_payload);

private:
    int mWidth;
    int mHeight;
    int mFps;
    int mBitrate;
    // yuv-->h264 平台 容器 x264_picture_t=bytebuffer
    x264_picture_t *pic_in = nullptr;
    int ySize;
    int uvSize;
    // 编码器
    x264_t *videoCodec = nullptr;
};


#endif // MEDIASTUDY_X264HELPER_H
